From 32884f0a50fc77a12073c6ae4c8c08186652576a Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 23 Jul 2014 08:49:02 -0700 Subject: [PATCH] Filter the current package out of override paths The current package being built should never be overridden, only its dependencies. Closes #225 --- src/cargo/ops/cargo_compile.rs | 15 ++++++++--- tests/test_cargo_compile_path_deps.rs | 36 +++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/src/cargo/ops/cargo_compile.rs b/src/cargo/ops/cargo_compile.rs index 26cb33d21..a6f894d0c 100644 --- a/src/cargo/ops/cargo_compile.rs +++ b/src/cargo/ops/cargo_compile.rs @@ -60,7 +60,8 @@ pub fn compile(manifest_path: &Path, } let user_configs = try!(config::all_configs(os::getcwd())); - let override_ids = try!(source_ids_from_config(&user_configs)); + let override_ids = try!(source_ids_from_config(&user_configs, + manifest_path.dir_path())); let source_ids = package.get_source_ids(); let (packages, resolve) = { @@ -107,8 +108,8 @@ pub fn compile(manifest_path: &Path, Ok(test_executables) } -fn source_ids_from_config(configs: &HashMap) - -> CargoResult> { +fn source_ids_from_config(configs: &HashMap, + cur_path: Path) -> CargoResult> { debug!("loaded config; configs={}", configs); let config_paths = configs.find_equiv(&"paths").map(|v| v.clone()); @@ -118,7 +119,13 @@ fn source_ids_from_config(configs: &HashMap) internal("invalid configuration for the key `path`") })); - Ok(paths.iter().map(|p| SourceId::for_path(&Path::new(p.as_slice()))).collect()) + // Make sure we don't override the local package, even if it's in the list + // of override paths + Ok(paths.iter().filter(|p| { + cur_path != os::make_absolute(&Path::new(p.as_slice())) + }).map(|p| { + SourceId::for_path(&Path::new(p.as_slice())) + }).collect()) } fn scrape_target_config(config: &mut Config, diff --git a/tests/test_cargo_compile_path_deps.rs b/tests/test_cargo_compile_path_deps.rs index d1d7b06c1..3d73e809c 100644 --- a/tests/test_cargo_compile_path_deps.rs +++ b/tests/test_cargo_compile_path_deps.rs @@ -505,3 +505,39 @@ test!(error_message_for_missing_manifest { p.root().join_many(&["src", "bar"]).display()))); }) + +test!(override_self { + let bar = project("bar") + .file("Cargo.toml", r#" + [package] + + name = "bar" + version = "0.5.0" + authors = ["wycats@example.com"] + "#) + .file("src/lib.rs", ""); + + let p = project("foo"); + let root = p.root().clone(); + let p = p + .file(".cargo/config", format!(r#" + paths = ['{}'] + "#, root.display())) + .file("Cargo.toml", format!(r#" + [package] + + name = "foo" + version = "0.5.0" + authors = ["wycats@example.com"] + + [dependencies.bar] + path = '{}' + + "#, bar.root().display())) + .file("src/lib.rs", "") + .file("src/main.rs", "fn main() {}"); + + bar.build(); + assert_that(p.cargo_process("cargo-build"), execs().with_status(0)); + +}) -- 2.30.2